import { fetch as tauriFetch } from '@tauri-apps/plugin-http'

let lastController = null;

export default async function fetch(url, options) {
    if (lastController) lastController.abort();
    lastController = new AbortController();
    try {
        return await tauriFetch(url, { ...options, signal: lastController.signal });
    } catch (e){
        return e;
    } finally {
        // 3. 请求完成后清理（可选，防止内存泄漏）
        if (lastController?.signal.aborted) lastController = null;
    }
}